﻿<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8" />
    <title>数据源管理</title>
    <link href="../lib/layui/css/layui.min.css" rel="stylesheet" />
    <link href="../x-admin/css/font.css" rel="stylesheet" />
    <link href="../x-admin/css/xadmin.css" rel="stylesheet" />
    <script type="text/javascript" src="../lib/Base64/base64.min.js"></script>
    <script type="text/javascript" src="../linq.js/linq.js"></script>
    <script src="../lib/layui/layui.js"></script>
</head>
<body>
    <div class="layui-card">
        <form class="layui-form layui-card-header layuiadmin-card-header-auto" id="sourceSearchForm" lay-filter="sourceSearchForm" style="padding-top:10px;">
            <div class="layui-form-item" style="margin-top:5px; margin-bottom:0;">
                <label class="layui-form-label">案件类型</label>
                <div class="layui-input-inline">
                    <select id="caseTypeCode" name="caseTypeCode" lay-filter="caseTypeCode"></select>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">数据源编号</label>
                    <div class="layui-input-block">
                        <input class="layui-input" name="code" type="text" placeholder="数据源编号(支持模糊匹配)" autocomplete="off" />
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">数据源名称</label>
                    <div class="layui-input-block">
                        <input class="layui-input" name="name" type="text" placeholder="数据源名称(支持模糊匹配)" autocomplete="off" />
                    </div>
                </div>
                <div class="layui-inline">
                    <a class="layui-btn" href="javascript:;" lay-submit lay-filter="load" id="load">搜索</a>
                </div>
            </div>
        </form>
        <table id="sourceTab" lay-filter="sourceTab"></table>

    </div>
    <script type="text/html" id="sourcetoolbar">
        <div class="layui-btn-container">
            <a class="layui-btn" lay-event="create">添加数据源</a>
        </div>
    </script>
    <script type="text/html" id="sourceBar">
        <a title="编辑" href="javascript:;" lay-event="edititem">
            <i class="layui-icon">&#xe642;</i>编辑
        </a>
        <a title="删除" href="javascript:;" lay-event="delitem">
            <i class="layui-icon">&#xe640;</i>删除
        </a>
    </script>
    <script>
        layui.use(['table','form'], function () {
            var table = layui.table;
            var form = layui.form;
            //加载部门下拉框数据
            layui.$.ajax({
                type: 'get',
                url: localStorage.getItem('hosttingaddr') + '/api/DataSource/getcasetypes',
                async: false,
                success: function (re) {
                    if (re.code == 1) {
                        layui.$("#caseTypeCode").append("<option value=''>请选择</option>");
                        for (var i = 0; i < re.data.length; i++) {
                            layui.$("#caseTypeCode").append("<option value='" + re.data[i].caseTypeCode + "'>" + re.data[i].caseTypeName + "</option>");
                        }
                        form.render();
                    }
                }
            });

            //第一个实例
            $tab = table.render({
                elem: '#sourceTab'
                , url: localStorage.getItem('hosttingaddr') + '/api/dataSource/index' //数据接口
                , toolbar: '#sourcetoolbar'
                , page: true
                , cols: [[ //表头
                    { field: 'id', title: 'ID', align: 'center' }
                    , { field: 'caseTypeCode', title: '案件类型编号', align: 'center' }
                    , { field: 'caseTypeName', title: '案件类型名称', align: 'center' }
                    , { field: 'code', title: '数据源编号', align: 'center' }
                    , { field: 'name', title: '数据源名称', align: 'center' }
                    , { title: '操作', align: 'center', toolbar: '#sourceBar' }
                ]]
                , where: getWhere()
            });
            //监听行工具事件
            table.on('tool(sourceTab)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                var data = obj.data //获得当前行数据
                    , layEvent = obj.event; //获得 lay-event 对应的值
                var fileN = data.path;
                if (layEvent == 'edititem') {
                    layer.open({
                        type: 2,
                        title: '数据源',
                        maxmin: true,
                        shadeClose: true, //点击遮罩关闭层
                        area: ['600px', '420px'],
                        content: 'sourceedit.html' + '?id=' + data.id// iframe链接地址
                    });

                } else if (layEvent == 'delitem') {
                    layer.confirm('确认要删除吗？', function (index) {
                        //发异步删除数据
                        layui.$.ajax({
                            type: "post",
                            url: localStorage.getItem('hosttingaddr') + '/api/DataSource/deletedatasource?id=' + data.id,
                            success: function (data) {
                                layer.msg('已删除!', { icon: 1, time: 1000 });
                                table.reload("sourceTab");
                            }
                        });

                    });
                }
            });

            table.on('toolbar(sourceTab)', function (obj) {
                var event = obj.event;
                switch (event) {
                    case "create":
                        layer.open({
                            type: 2,
                            title: '模块导航内容',
                            maxmin: true,
                            shadeClose: true, //点击遮罩关闭层
                            area: ['600px', '600px'],
                            content: 'sourcecreate.html'
                        });
                        break;
                    case "set":
                        layui.$.ajax({
                            type: 'get',
                            url: localStorage.getItem('hosttingaddr') + '/api/DataSource/setdatasource',
                            async: false,
                            success: function (re) {
                                console.log(re);
                            }
                        });
                    default: break;
                }
            })

            //搜索按钮事件
            layui.form.on("submit(load)", function () {
                var where = getWhere();
                $tab.reload({
                    where: where,
                    page: { curr: 1 }
                });
                return false;
            });
            //搜索条件
            function getWhere() {
                var where = layui.form.val("sourceSearchForm");
                return where;
            }
        });
    </script>
</body>
</html>